<template>
	<view class="apps">
		<view class="flex fdc"><image src="https://pics.sciencemate.com/Fp-Fh3vAEs8_cWSUcX5ZEBSONof_" Mode="aspectFit" style="height:220rpx;width:750rpx;"></image></view>
		<view class="mlr20 mt20 ptb20 plr20 bgwhite">
			<view class="pl20 flex aic bdt">
				<uv-subsection :list="sublist" :current="current" @change="subchange"></uv-subsection>
			</view>
			<view class="flex fdc"  v-if="list.length >0">
				<view class=" mtb20 ptb10 plr10 bgwhite flex fdc" v-for="(item,index) in list" :key="index">
					<view class="flex fdc" @click="handle(item.id)">
						<view class="tic">
							<image :src="item.mobileImg || item.pcImg "></image>
						</view>
						<view class="ptb20 f14 fweight4">{{item.name}}</view>
						<view class="flex jcsb f12">
							<view class="c666 flex aic">
								<uv-icon name="clock" size="20"></uv-icon>
								<text>{{ timeFormat(item.st) }}</text>
							</view>
							<view class="c888  flex aic" v-if="item.city != ''">
								<uv-icon name="map" size="20"></uv-icon>
								<text>{{ item.city}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else>
				<uv-empty mode="data"></uv-empty>
			</view>
		</view>
		<uv-toast ref="toast"></uv-toast>
	</view>
</template>

<script setup>
	import { ref, reactive, nextTick, toRefs, watch, getCurrentInstance } from 'vue';
	import { onLoad, onShow,onReachBottom } from '@dcloudio/uni-app'
	const { proxy } = getCurrentInstance();
	const { $onLaunched } = proxy;
	import { timeFormat } from '@/uni_modules/uv-ui-tools/libs/function/index.js';
	import { getConferenceList, getMyConferenceList } from '@/common/conference/index.js'
	import { useUserInfo } from '@/stores/userInfo.js'
	const page = ref(1)
	const pageMore = ref(true)
	const list = ref([])
	const toast = ref(null)
	const current = ref(0)
	const sublist = ref(['最新会议','我参加的'])
	const getList = ()=>{
		getConferenceList().then((rlt)=>{
			if(rlt.code == 0){
				list.value = rlt.data.list;
			}else{
				uni.showToast({
					title:rlt.message
				})
			}
		})
	}
	const myPage = ()=>{
		const userInfo = useUserInfo();
		if(!userInfo.isLogin()){
			list.value =[];
			uni.showToast({
				title:'请登录',
				duration:3000,
				complete:function(){
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}
			})
			current.value=0
			return 
		}
		let pageNum = page.value
		getMyConferenceList(pageNum).then((rlt)=>{
			if(rlt.code == 0){
				if(pageNum == 1){
					list.value = rlt.data.list
				}else{
					list.value.push(... rlt.data.list)
				}
				if(rlt.data.list<10){
					pageMore.value = false
				}
				page.value++
			}
		})
	}
	const subchange = (e)=>{
		current.value = e;
		page.value = 1
		
		if(e == 1){
			myPage()
		}else{
			getList();
		}
	}
	const handle = (id)=>{
		uni.navigateTo({
			url:"/pages/detail/detail?id="+id,
		})
	}
	onLoad(async ()=>{
	    await $onLaunched;
		
	})
	onShow(()=>{
		if(current.value == 0){
			getList()
		}else{
			if(pageMore.value==true){
				myPage();
			} 
		}
	})
	onReachBottom(()=>{
		if(current.value ==1 && pageMore.value){
			myPage()
		}
	})
</script>

<style lang="scss" scope>
	.tic{height:220rpx;}
	.tic image{width:100%;height:100%}
</style>
